﻿using BackendLogic;
using BackendLogic.BaseLogic;
using BackstageWeb.App_Start.Helper;
using Ioc.Unity;
using MappingDTO.Admin;
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using ToolsModel;

namespace BackstageWeb.Areas.Admin.Controllers
{
    public class HomeController : BaseController
    {
        // GET: Admin/Home
        [UserAuthorization(true, 2)]
        public ActionResult Index()
        {
            ViewBag.Name = "管理员";
            return View();
        }


        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, 2)]
        public ActionResult HomeMain()
        {
            return View();
        }

        /// <summary>
        /// 获取功能
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, 1)]
        public ActionResult LoadMenus()
        {
            var resultInfo = new ResultJsonInfo<IList<SysMenuRetDTO>>();
            try
            {
                ISysMenuService sysMenuService = UnityCIContainer.Instance.GetService<ISysMenuService>();
                resultInfo = sysMenuService.LoadMenus();
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Msg = ex.Message;
            }
            return ReturnResult(resultInfo);
        }



        /// <summary>
        /// 退出
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, 1)]
        public ActionResult ExitLogin()
        {

            var resultInfo = new ResultJsonInfo<String>();
            try
            {
                UserSession.RemoveLoginUser(); 
                resultInfo.Success = true;
                resultInfo.Code = 1;
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Msg = ex.Message;
            }
            return ReturnResult(resultInfo);

           
        }
    }

}